package model;

import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import java.util.Observable;

import ai.ABPruningPlayer;
import ai.BestChoiceType;
import ai.HeuristicType;
import ai.MiniMaxPlayer;

public class GameConfiguration {
	private int rows, cols;
	private PlayerType player1, player2;
	private int depth1, depth2;
	private boolean enDepthCheck1, enDepthCheck2, enThreatFinder1,
			enThreatFinder2, enTB1, enTB2, enDT1, enDT2, enTactics1,
			enTactics2, enPotentialThreat1, enPotentialThreat2, enReordering1, enReordering2;
	BestChoiceType choiceType1, choiceType2;

	public GameConfiguration(int rows, int cols, PlayerType player1,
			PlayerType player2, int depth1, int depth2, boolean enDepthCheck1,
			boolean enDepthCheck2, boolean enThreatFinder1,
			boolean enThreatFinder2, boolean enPotentialThreat1,
			boolean enPotentialThreat2, boolean enTB1, boolean enTB2,
			boolean enDT1, boolean enDT2, boolean enTactics1,
			boolean enTactics2, BestChoiceType choiceType1,
			BestChoiceType choicheType2, boolean enReordering1, boolean enReordering2) {
		super();
		this.rows = rows;
		this.cols = cols;
		this.player1 = player1;
		this.player2 = player2;
		this.depth1 = depth1;
		this.depth2 = depth2;
		this.enDepthCheck1 = enDepthCheck1;
		this.enDepthCheck2 = enDepthCheck2;
		this.enThreatFinder1 = enThreatFinder1;
		this.enThreatFinder2 = enThreatFinder2;
		this.enTB1 = enTB1;
		this.enTB2 = enTB2;
		this.enDT1 = enDT1;
		this.enDT2 = enDT2;
		this.enTactics1 = enTactics1;
		this.enTactics2 = enTactics2;
		this.choiceType1 = choiceType1;
		this.choiceType2 = choicheType2;
		this.enPotentialThreat1 = enPotentialThreat1;
		this.enPotentialThreat2 = enPotentialThreat2;
		this.enReordering1 = enReordering1;
		this.enReordering2 = enReordering2;
	}
	
	

	public boolean isEnReordering1() {
		return enReordering1;
	}



	public boolean isEnReordering2() {
		return enReordering2;
	}



	public BestChoiceType getChoiceType1() {
		return choiceType1;
	}



	public BestChoiceType getChoiceType2() {
		return choiceType2;
	}



	public PlayerType getPlayer1() {
		return player1;
	}

	public void setPlayer1(PlayerType player1) {
		this.player1 = player1;
	}

	public PlayerType getPlayer2() {
		return player2;
	}

	public void setPlayer2(PlayerType player2) {
		this.player2 = player2;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

	public int getCols() {
		return cols;
	}

	public void setCols(int cols) {
		this.cols = cols;
	}

	public int getDepth1() {
		return depth1;
	}

	public void setDepth1(int depth1) {
		this.depth1 = depth1;
	}

	public int getDepth2() {
		return depth2;
	}

	public void setDepth2(int depth2) {
		this.depth2 = depth2;
	}

	public AbstractPlayer[] createAbstractPlayers(Observable board) {
		AbstractPlayer players[] = new AbstractPlayer[2];

		ArrayList<HeuristicType> heuristics1 = (ArrayList<HeuristicType>) createHeuristicTypeList(
				enThreatFinder1, enTB1, enDT1, enTactics1, enPotentialThreat1);
		ArrayList<HeuristicType> heuristics2 = (ArrayList<HeuristicType>) createHeuristicTypeList(
				enThreatFinder2, enTB2, enDT2, enTactics2, enPotentialThreat2);

		players[0] = createPlayer(player1, Color.RED, board, depth1,
				enDepthCheck1, choiceType1, enReordering1, heuristics1);
		players[1] = createPlayer(player2, Color.YELLOW, board, depth2,
				enDepthCheck2, choiceType2, enReordering2, heuristics2);
		return players;
	}

	private List<HeuristicType> createHeuristicTypeList(boolean enThreatFinder,
			boolean enTB, boolean enDT, boolean enTactics,
			boolean enPotentialThreat) {
		ArrayList<HeuristicType> heuristics = new ArrayList<HeuristicType>();
		if (enThreatFinder)
			heuristics.add(HeuristicType.THREATFINDER);
		if (enTB)
			heuristics.add(HeuristicType.THREATBONUS);
		if (enDT)
			heuristics.add(HeuristicType.DOUBLETHREAT);
		if (enTactics)
			heuristics.add(HeuristicType.TACTICS);
		if (enPotentialThreat)
			heuristics.add(HeuristicType.POTENTIALTHREAT);
		return heuristics;
	}

	private AbstractPlayer createPlayer(PlayerType player, Color color,
			Observable board, int maxDepth, boolean enDepthCheck,
			BestChoiceType choiceType, boolean enReordering,
			List<HeuristicType> heuristics) {

		String description = "";

		AbstractPlayer p = null;
		switch (player) {
		case HUMAN:
			description = "Human";
			p = new HumanPlayer(color, board);
			break;
		case RANDOM:
			description = "Random";
			p = new RandomPlayer(color);
			break;
		case ABPRUNING:
			description = "ABPruning";
			p = new ABPruningPlayer(color, description, maxDepth, enDepthCheck,
					choiceType, enReordering, heuristics);
			break;
		case MINIMAX:
			description = "Minimax";
			p = new MiniMaxPlayer(color, description, maxDepth, enDepthCheck,
					choiceType, enReordering, heuristics);
			break;
		
		}

		return p;
	}



	public boolean isEnDepthCheck1() {
		return enDepthCheck1;
	}



	public boolean isEnDepthCheck2() {
		return enDepthCheck2;
	}



	public boolean isEnThreatFinder1() {
		return enThreatFinder1;
	}



	public boolean isEnThreatFinder2() {
		return enThreatFinder2;
	}



	public boolean isEnTB1() {
		return enTB1;
	}



	public boolean isEnTB2() {
		return enTB2;
	}



	public boolean isEnDT1() {
		return enDT1;
	}



	public boolean isEnDT2() {
		return enDT2;
	}



	public boolean isEnTactics1() {
		return enTactics1;
	}



	public boolean isEnTactics2() {
		return enTactics2;
	}



	public boolean isEnPotentialThreat1() {
		return enPotentialThreat1;
	}



	public boolean isEnPotentialThreat2() {
		return enPotentialThreat2;
	}
}
